package filters.pull;

import helper.PlanarImageWrapper;

import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.KernelJAI;

import org.apache.log4j.Logger;

import at.fhv.framework.filter.PassivePullFilter;
import at.fhv.framework.interfaces.Pull;

/**
 * The OpeningFilter class.
 * 
 * @author Michael Sieber
 */
public class ErodePullFilter extends PassivePullFilter<PlanarImageWrapper, PlanarImageWrapper> 
{
	private static Logger LOGGER = Logger.getLogger(ErodePullFilter.class);

	public ErodePullFilter(Pull<PlanarImageWrapper> source) 
	{
		super(source);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	protected boolean execute(PlanarImageWrapper entity, PlanarImageWrapper data) 
	{
		LOGGER.debug("eroding operation");
		
		KernelJAI kernel = new KernelJAI(10, 10, new float[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1,														  
														       1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
		ParameterBlock pb = new ParameterBlock();
		pb.addSource(data.getImage());
		pb.add(kernel);

		entity.setImage(JAI.create("erode", pb));
		return true;
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	protected PlanarImageWrapper createEntity() 
	{
		return new PlanarImageWrapper();
	}

}
